﻿
var YearStr,MonthStr,DayStr,HourStr,MinuteStr;
var week,week_one;
var WeekArr = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var dt = new Date();
YearStr = dt.getYear();
MonthStr = dt.getMonth() + 1;
DayStr = dt.getDate();
HourStr = "";
MinuteStr = "";
week = dt.getDay();
currentDate = dt.getYear() +"-"+ (dt.getMonth() + 1) +"-"+ dt.getDate();
document.write("<DIV id=idCalendar name=idCalendar style='position:absolute;top:0px;left:0px;width:100%;background-color: #FFFFFF;'></DIV>");
function initCalendar(){
var CaleHTML="";
CaleHTML += "<TABLE border=0 cellspacing=0 cellpadding=0 width='100%' ID='Table1'>";
CaleHTML += "<TR height=20>";
CaleHTML += "<TD align=right class='CalendarTool'>";
CaleHTML += "<select id='SelectYear' name='SelectYear' onchange='ChangeYear(this.value);' style='width:65px;'>";
for (i=1951;i<2051;i++){
CaleHTML += "<option value='" + i + "'";
if (i==YearStr){
CaleHTML += " selected";}
CaleHTML += ">" + i + "</option>";}
CaleHTML += "</select>";
CaleHTML += "<select id='SelectMonth' name='SelectMonth' onchange='ChangeMonth(this.value);' style='width:50px;'>";
for (i=1;i<13;i++){
CaleHTML += "<option value='" + i + "'";
if (i==MonthStr){
CaleHTML += " selected";}
CaleHTML += ">" + i + "</option>";}
CaleHTML += "</select>"; 
CaleHTML += "</TD>";
CaleHTML += "</TR>";
CaleHTML += "<TR><TD>";
CaleHTML += "<TABLE border=0 cellspacing=0 cellpadding=0 width='100%' ID='Table2'><TR bgcolor=#7288AC height=20 align=center>";
for(var i=0; i<WeekArr.length; i++){
CaleHTML += "<TD align=center class='CalendarWeek'>" + WeekArr[i] + "</TD>";}
CaleHTML += "</TR>";
CaleHTML += bodyCalendar();
CaleHTML += "</TABLE>";
CaleHTML += "</TD></TR>";
CaleHTML += "<TR><TD class='CalendarTool' height=20 align=center style='cursor:hand;' onclick='TodayClick();'>Today：<Font color=red>"+ currentDate +"</font></TD></TR>";
//CaleHTML += "<TR><TD class='CalendarTool' height=20 align=right>";
//CaleHTML += "<select id='SelectHour' name='SelectHour' style='width:65px;' onchange='HourStr=this.value;'>";
//CaleHTML += "<option value=''></option>";
//for (i=7;i<21;i++){
//CaleHTML += "<option value='" + i + "'>" + i + "</option>";}
//CaleHTML += "</select>";
//CaleHTML += "<select id='SelectMinute' name='SelectMinute' style='width:50px;' onchange='MinuteStr=this.value;'>";
//CaleHTML += "<option value=''></option>";
//for (i=0;i<60;i=i+5){
//CaleHTML += "<option value='" + i + "'>" + i + "</option>";}
//CaleHTML += "</select>"; 
//CaleHTML += "</TD></TR>";
CaleHTML += "</TABLE>";
return CaleHTML;}
function bodyCalendar(){
var ResultStr = "<TR>";
var tempStr = "" + MonthStr + "/1/" + YearStr;
var d = new Date(tempStr);
week_one = d.getDay();
for(var i=0;i<week_one;i++){
ResultStr += "<TD></TD>";}
var bYear = YearStr%4;
var maxDay;
switch(parseInt(MonthStr)){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxDay = 31;
break;
case 2:
if(bYear==0){
maxDay = 29;}
else{
maxDay = 28;}
break;
default:
maxDay = 30;
break;}
var k;
var bday;
for(var i=0;i<maxDay;i++){
if((i+1) == DayStr){
bday = " class='CalendarCellToday'";}
else{
bday = " class='CalendarCell'";}
BRStr = i+week_one+1;
if(BRStr>=7 && BRStr%7==0){
ResultStr += "<TD height=25 align=center style='cursor:hand;'"+ bday +" onmouseover='TDMove()' onmouseout='TDOut()' onclick='TDClick()'>"+ eval(i+1) +"</TD></TR><TR>";
k=0;}
else{
ResultStr += "<TD height=25 align=center style='cursor:hand;'"+ bday +" onmouseover='TDMove()' onmouseout='TDOut()' onclick='TDClick()'>"+ eval(i+1) +"</TD>";
k+=1;}}
for(var i=0;i<7-k;i++){
ResultStr += "<TD></TD>";}
ResultStr += "</TR>";
return ResultStr;}
function ChangeYear(SelectYear){
YearStr = SelectYear;
idCalendar.innerHTML = initCalendar();}
function ChangeMonth(SelectMonth){
MonthStr = SelectMonth;
idCalendar.innerHTML = initCalendar();}
function TDMove(){
var obj = event.srcElement;
obj.className = "CalendarCellHover";}
function TDOut(){
var obj = event.srcElement;
if(parseInt(obj.innerText) == DayStr){
obj.className = "CalendarCellToday";}
else{
obj.className = "CalendarCell";}}

function GetTimeStr()
{
	if (HourStr == "")
	{
		return "";
	}
	else
	{
		if (MinuteStr == "")
		{
			return " " + HourStr + ":0";
		}
		else
		{
			return " " + HourStr + ":" + MinuteStr;
		}
	}
}

function TDClick()
{
	DayStr = event.srcElement.innerText;
	if(MonthStr<10)
	    MonthStr = "0" + MonthStr;
	if(DayStr<10)
	    DayStr = "0" + DayStr;
	    
	self.returnValue = YearStr + "-" + MonthStr + "-" + DayStr;// + GetTimeStr();
	self.close();
}

function TodayClick()
{
	DayStr = event.srcElement.innerText;
	self.returnValue = currentDate;// + GetTimeStr();
	self.close();
}

idCalendar.innerHTML = initCalendar();
